// pages/myPages/contactsPage/contactsPage.js
var request = require('./request.js')

//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    contacts: [],
    majorMain: '',
    checked:true,
    changeId:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      changeId:options.changeId || 0
    })
    // this.getContact();
  },
  getContact: function (e) {
    var that = this;
    var data = {
      access_token: wx.getStorageSync('createUser').access_token
    };
    request.contactGet(data, function (d) {
      if (d.data == null) {
        that.setData({
          majorMain: ''
        })
        wx.removeStorageSync('userMessage');
      } else {
        that.setData({
          majorMain: '1',
          contacts: d.data
        });
      }
    });
  },
  addContactsPage: function (e) {
    wx.navigateTo({
      url: './addContactsPage/addContactsPage'
    })
  },
  changeContactsPage: function (e) {
    var index = e.currentTarget.dataset.index;
    var id = this.data.contacts[index].id;
    var userName = this.data.contacts[index].name;
    var WalletAddress = this.data.contacts[index].wallet_addr;
    var MobilePhoneNo = this.data.contacts[index].mobile;
    var WalletType = this.data.contacts[index].coin_symbol;
    var email = this.data.contacts[index].email;
    var note = this.data.contacts[index].remark;
    wx.navigateTo({
      url: './changeContactsPage/changeContactsPage?id=' + id + '&&userName=' + userName + '&&WalletAddress=' + WalletAddress + '&&MobilePhoneNo=' + MobilePhoneNo + '&&WalletType=' + WalletType + '&&email=' + email + '&&note=' + note + ''
    })
  },
  radioChange: function (e) {
    var index = e.detail.value 
    var userMessage = this.data.contacts[index]
    wx.setStorageSync('userMessage', userMessage)

    var chooseKey = wx.getStorageSync('chooseKey')
    if (chooseKey ==1){
      
    }else{
      wx.navigateBack({
        delta: 1
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      setLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']
    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].TheContact : wx.T.locales['en'].TheContact
    })
    this.getContact();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})